package com.wqtz.chechai.view.activities;

import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.wqtz.chechai.R;
import com.wqtz.chechai.adapter.CarRentTimeAdapter;
import com.wqtz.chechai.base.BaseActivity;
import com.wqtz.chechai.bean.CarTime;
import com.wqtz.chechai.presenter.BasePresent;
import com.wqtz.chechai.utils.ToastUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目名称： CheChai
 * 创建人 : Liberation
 * 创建时间: 2017/2/6 15:33
 */

public class CarTimeSelectedActivity extends BaseActivity implements CarRentTimeAdapter.itemClick {
	@BindView(R.id.iv_back)
	ImageView mIvBack;
	@BindView(R.id.tv_title)
	TextView mTvTitle;
	@BindView(R.id.lv)
	ListView mLv;
	ArrayList<CarTime> mCarTimes;
	CarRentTimeAdapter mCarRentTimeAdapter;
	private AlertDialog dia;
	private View view;

	@Override
	public void init() {
		ButterKnife.bind(this);
		mCarTimes = new ArrayList<>();
		mCarRentTimeAdapter = new CarRentTimeAdapter(R.layout.item_car_time_select);

	}

	@Override
	public void loadData() {
		CarTime carTime1 = new CarTime();
		CarTime carTime2 = new CarTime();
		CarTime carTime3 = new CarTime();
		carTime1.days=7;
		carTime1.count=2.0;
		carTime2.days=15;
		carTime2.count=1.0;
		carTime3.days=30;
		carTime3.count=0.5;
		mCarTimes.add(carTime1);
		mCarTimes.add(carTime2);
		mCarTimes.add(carTime3);
		mCarRentTimeAdapter.addData(mCarTimes);
		mLv.setAdapter(mCarRentTimeAdapter);
		mCarRentTimeAdapter.setOnItemClick(this);

	}

	@Override
	public int setContentViews() {
		return R.layout.activity_cartimeseleted;
	}

	@Override
	public BasePresent createPresenter() {
		return null;
	}



	@OnClick(R.id.iv_back)
	public void onClick() {
		finish();
	}

	@Override
	public void onitemClickCallBack(int position) {
		Intent intent = new Intent();
		intent.putExtra("days",mCarTimes.get(position).days);
		setResult(RESULT_OK,intent);
		finish();

	}

	@Override
	public void imageClickCallBack(int position) {
		view = LayoutInflater.from(this).inflate(R.layout.dialog_view,null);
		Button confirm = (Button) view.findViewById(R.id.btn_confirm);
		confirm.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				dia.dismiss();
			}
		});
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setView(view);
		dia = builder.create();
		dia.show();
	}

	@Override
	protected void onResume() {
		super.onResume();
		activitys.add(this); //添加当前的activity
	}
}
